Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

each-async

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

each-async

Async concurrent iterator

  • 0.1.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is each-async?

The each-async npm package allows you to asynchronously iterate over an array, performing asynchronous operations on each item in the array. It is useful for scenarios where you need to handle asynchronous tasks in a sequential manner.

What are each-async's main functionalities?

Asynchronous Iteration

This feature allows you to iterate over an array and perform asynchronous operations on each item. The `asyncOperation` function is called for each item in the array, and the `done` callback is called when the operation is complete. The final callback is called when all items have been processed.

const eachAsync = require('each-async');

const items = [1, 2, 3, 4, 5];

function asyncOperation(item, index, done) {
  setTimeout(() => {
    console.log('Processing item:', item);
    done();
  }, 1000);
}

eachAsync(items, asyncOperation, (err) => {
  if (err) {
    console.error('Error:', err);
  } else {
    console.log('All items have been processed.');
  }
});

Error Handling

This feature demonstrates how to handle errors during the asynchronous iteration. If an error occurs during the processing of an item, the `done` callback is called with an error object, and the final callback receives the error.

const eachAsync = require('each-async');

const items = [1, 2, 3, 4, 5];

function asyncOperation(item, index, done) {
  setTimeout(() => {
    if (item === 3) {
      done(new Error('An error occurred with item 3'));
    } else {
      console.log('Processing item:', item);
      done();
    }
  }, 1000);
}

eachAsync(items, asyncOperation, (err) => {
  if (err) {
    console.error('Error:', err);
  } else {
    console.log('All items have been processed.');
  }
});

Other packages similar to each-async

Keywords

FAQs

Package last updated on 29 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc